package git.bds.nyc.admin.controller.gx;

import git.bds.nyc.communal.model.domain.Agreement;
import git.bds.nyc.communal.model.dto.AgreementDTO;
import git.bds.nyc.communal.service.agreement.AgreementService;
import git.bds.nyc.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 成大事
 * @since 2023-06-07 20:14:13
 */
@Api(tags = "协议管理")
@Validated
@RestController
@RequestMapping("/admin/agreement")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class AgreementManageController {


    private final AgreementService agreementService;


    /**
     * 创建协议
     *
     * @param agreementDTO 协议dto
     * @return {@link R}<{@link Boolean}>
     */
    @PostMapping("/createAgreement")
    @ApiOperation("新建协议")
    public R<Boolean> createAgreement(
            @Validated @ModelAttribute AgreementDTO agreementDTO
    ){
        return R.decide(agreementService.createAgreement(agreementDTO));
    }

    /**
     * 删除协议
     *
     * @param id 身份证
     * @return {@link R}<{@link Boolean}>
     */
    @PostMapping("/delAgreement/{id}")
    @ApiOperation("删除协议")
    public R<Boolean> delAgreement(
           @PathVariable("id") Long id
    ){
        return R.decide(agreementService.delAgreement(id));
    }


    /**
     * 获取协议列表
     *
     * @return {@link R}<{@link List}<{@link Agreement}>>
     */
    @PostMapping("/getAgreementList")
    @ApiOperation("获取协议列表")
    public R<List<Agreement>> getAgreementList(){
        return R.ok(agreementService.list());
    }
}
